/**
 * Eclipse Outliner
 * Copyright (C) 2006 Jeff Mesnil
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */
package net.jmesnil.outliner;

import net.jmesnil.outliner.ui.actions.OPMLCreateNewAction;
import net.jmesnil.outliner.ui.actions.OpenExternalFileAction;
import net.jmesnil.outliner.ui.actions.OutlineIndentAction;
import net.jmesnil.outliner.ui.actions.OutlineInsertNewAction;
import net.jmesnil.outliner.ui.actions.OutlineOutdentAction;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

    private IWorkbenchAction newOPMLAction;

    private IWorkbenchAction openFileAction;

    private IWorkbenchAction exitAction;

    private IWorkbenchAction aboutAction;

    private IWorkbenchAction saveAction;

    private IWorkbenchAction saveAsAction;

    private IAction indentAction;

    private IAction outdentAction;

    private IAction insertNewAction;

    public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }

    protected void makeActions(IWorkbenchWindow window) {
        newOPMLAction = new OPMLCreateNewAction(window);
        register(newOPMLAction);
        openFileAction = new OpenExternalFileAction(window);
        register(openFileAction);
        saveAction = ActionFactory.SAVE.create(window);
        register(saveAction);
        saveAsAction = ActionFactory.SAVE_AS.create(window);
        register(saveAsAction);

        indentAction = new OutlineIndentAction(window);
        register(indentAction);
        outdentAction = new OutlineOutdentAction(window);
        register(outdentAction);
        insertNewAction = new OutlineInsertNewAction(window);
        register(insertNewAction);

        exitAction = ActionFactory.QUIT.create(window);
        exitAction.setText("&Quit");
        exitAction.setAccelerator(SWT.MOD1 | 'Q');
        register(exitAction);
        
        aboutAction = ActionFactory.ABOUT.create(window);
        register(aboutAction);
    }

    protected void fillMenuBar(IMenuManager menuBar) {
        MenuManager fileMenu = new MenuManager("&File", "file");
        fileMenu.add(newOPMLAction);
        fileMenu.add(openFileAction);
        fileMenu.add(new Separator());
        fileMenu.add(saveAction);
        fileMenu.add(saveAsAction);
        fileMenu.add(new Separator());
        fileMenu.add(exitAction);

        MenuManager organizeMenu = new MenuManager("&Organize", "organize");
        organizeMenu.add(insertNewAction);
        organizeMenu.add(new Separator());
        organizeMenu.add(indentAction);
        organizeMenu.add(outdentAction);

        MenuManager helpMenu = new MenuManager("&Help", "help");
        helpMenu.add(aboutAction);

        menuBar.add(fileMenu);
        menuBar.add(organizeMenu);
        menuBar.add(helpMenu);
    }
}
